
import store from '@/store'
import houseType from './houseType'
const BUSINESS = 'business'
const RENTING = 'renting'

let houseTypeList = null

export function setHouseTypeList() {
	// houseTypeList = store.getters.houseTypeList
	houseTypeList = houseType.data
}

const getOptionList = (str) => {
	return houseTypeList[str].map(item => item.itemName)
}

const basicData = [
	// 小区选项配置(二手房和租房都有)
	{
		id: 'location',
		event: 'jump',
		output: 'format',
		type: 'input',
 		isReadonly: true,
		field: [
			{ name: '小区', value: '', active: true, type: 'text', required: true, isEmpty: false }
		],
		apply: [BUSINESS, RENTING],
		placeholder: '填写小区名称'
	},
	// 楼栋、单元、房号选项配置(二手房和租房都有)
	{
		id: 'address',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: false,
		field: [
			{ name: '楼栋', value: '', active: true,  type: 'text', required: true, unit: '栋',  isReadonly: false, isEmpty: false, placeholder: '请输入'  },
			{ name: '单元', value: '', active: false, type: 'text', required: false, unit: '单元', isReadonly: false,  isEmpty: false, placeholder: '请输入'  },
			{ name: '房号', value: '', active: false, type: 'text', required: true, unit: '室', isReadonly: false,  isEmpty: false, placeholder: '请输入'  }
		],
		placeholder: '请输入',
		apply: [BUSINESS, RENTING],
		plugin: function(item) {
			let len = item.value.length
			let bool = item.value.substring(len - item.unit.length, len) === item.unit
			if (!bool) item.value = item.value + item.unit
			return item
		}
	},
	// 楼层选项配置(二手房和租房都有)
	{
		id: 'floor',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		field: [
			{ 
				name: '楼层', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [2, 2],
				placeholder: '请选择',
				columns: function() {
					let indexs = this.defaultIndexs
					return [
						{
							values: (function(){
								let min = -2
								let max = 99
								let array = []
								for(let i = min; i <= max; i++) {
									if (i) array.push(`${i}层`)
								}
								return array
							})(),
							className: 'current-floor',
							defaultIndex: indexs[0]
						},
						{
							values: (function(){
								let min = 1
								let max = 99
								let array = []
								for(let i = min; i <= max; i++) {
									if (i) array.push(`共${i}层`)
								}
								return array
							})(),
							className: 'total-floor',
							defaultIndex: indexs[1]
						}
					]
				},
			}
		],
		plugin: function(value) {
			// let layer = value[0]
			// layer = parseInt(layer)
			// let str = ''
			// if (layer <= 7) {
			// 	str = '低层'
			// } else if (layer > 7 && layer <= 14) {
			// 	str = '中层'
			// } else {
			// 	str = '高层'
			// }
			// return (str + ' ' +value.join(" / "))
			return value.join(" / ")
		},
		apply: [BUSINESS, RENTING],
		placeholder: '请选择'
	},
	// 梯户比例配置(仅二手房有)
	{
		id: 'elevator',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		field: [
			{ 
				name: '梯户比例', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [2, 2],
				placeholder: '请选择',
				columns: function() {
					let indexs = this.defaultIndexs
					return [
						{
							values: (function(){
								let min = 1
								let max = 5
								let array = []
								for(let i = min; i <= max; i++) {
									array.push(`${i}梯`)
								}
								array.push('5梯以上')
								return array
							})(),
							className: 'ladder-number',
							defaultIndex: indexs[0]
						},
						{
							values: (function(){
								let min = 1
								let max = 10
								let array = []
								for(let i = min; i <= max; i++) {
									array.push(`${i}户`)
								}
								array.push('10户以上')
								return array
							})(),
							className: 'household-number',
							defaultIndex: indexs[1]
						}
					]
				},
			}
		],
		plugin: function(value) {
			return value.join(" / ")
		},
		apply: [BUSINESS],
		placeholder: '请选择'
	},
	// 建筑面积、套内面积、价格选项配置(仅二手房有)
	{
		id: 'AreaAndPrice',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: false,
		field: [
			{ name: '建筑面积', value: '', active: true,  type: 'text', required: true, unit: '㎡',  isReadonly: false, isEmpty: false, placeholder: '请输入'  },
			{ name: '套内面积', value: '', active: false, type: 'text', required: true, unit: '㎡', isReadonly: false,  isEmpty: false, placeholder: '请输入'  },
			{ name: '出售价格', value: '', active: false, type: 'text', required: true, unit: '万', isReadonly: false,  isEmpty: false, placeholder: '请输入'  }
		],
		apply: [BUSINESS],
        placeholder: '请输入',
        plugin: function(item) {
            let len = item.value.length
            let bool = item.value.substring(len - item.unit.length, len) === item.unit
            if (!bool) item.value = item.value + item.unit
            return item
        }
	},
	// 建筑面积、出租价格 选项配置(仅租房有)
	{
		id: 'rentalprice',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: false,
		field: [
			{ name: '建筑面积', value: '', active: true,  type: 'text', required: true, unit: '㎡',  isReadonly: false, isEmpty: false, placeholder: '请输入'  },
			{ name: '出租价格', value: '', active: false, type: 'text', required: true, unit: '元', isReadonly: false,  isEmpty: false, placeholder: '请输入'  }
		],
		apply: [RENTING],
        placeholder: '请输入',
        plugin: function(item) {
            let len = item.value.length
            let bool = item.value.substring(len - item.unit.length, len) === item.unit
            if (!bool) item.value = item.value + item.unit
            return item
        }
	},
	// 户型、朝向、电梯选项配置(二手房和租房都有)
	{
		id: 'houseInfo',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [BUSINESS, RENTING],
		placeholder: '请选择',
		field: [
			{ 
				name: '户型', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [2, 2, 2],
				columns: function() {
					let indexs = this.defaultIndexs
					return [
						{
							values: (function(){
								let array = []
								let min = 1
								let max = 10
								for(let i = min ;i < max; i++) {
									array.push(`${i}室`)
								}
								return array
							})(),
							className: 'houseInfo-room',
							defaultIndex: indexs[0]
						},
						{
							values: (function(){
								let array = []
								let min = 0
								let max = 10
								for(let i = min ;i < max; i++) {
									array.push(`${i}厅`)
								}
								return array
							})(),
							className: 'apartment-hall',
							defaultIndex: indexs[1]
						},
						{
							values: (function(){
								let array = []
								let min = 0
								let max = 10
								for(let i = min ;i < max; i++) {
									array.push(`${i}卫`)
								}
								return array
							})(),
							className: 'apartment-toilet',
							defaultIndex: indexs[2]
						}
					]
				}
			},
			{ 
				name: '朝向', 
				value: '',
				active: false,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [2],
				placeholder: '请选择',
				classify: 'orientationsType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							// values: ['东','西','南','北','东南','西南','东北','西北','南北','东西'],
							values,
							className: 'apartment-direction',
							defaultIndex: indexs[0]
						}
					]
				},
			},
			{ 
				name: '电梯', 
				value: '',
				active: false,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'liftStatus_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							// values: ['无', '有'],
							values,
							className: 'apartment-elevator',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	// 房屋类型 / 产权年限 / 是否唯一 选项配置(仅二手房有)
	{
		id: 'houseAttribute',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [ BUSINESS ],
		placeholder: '请选择',
		field: [
			{ 
				name: '房屋类型', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				classify: 'houseType_list',
				defaultIndexs: [2],
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["普通住宅", "复式住宅", "公寓", "商住两用", "别墅"],
							className: 'house-type',
							defaultIndex: indexs[0]
						}
					]
				}
			},
			{ 
				name: '产权年限', 
				value: '',
				active: false,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'propertyYearsType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["40年产权", "50年产权", "70年产权"],
							className: 'house-years',
							defaultIndex: indexs[0]
						}
					]
				},
			},
			{ 
				name: '是否唯一', 
				value: '',
				active: false,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'uniqueStatus_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["不唯一", "唯一" ],
							className: 'house-only',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	// 房屋类型 / 付款方式 / 租期 选项配置(仅租房有)
	{
		id: 'houseAttribute',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [ RENTING ],
		placeholder: '请选择',
		field: [
			{ 
				name: '房屋类型', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [2],
				classify: 'houseType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["普通住宅", "复式住宅", "公寓", "商住两用", "别墅"],
							className: 'house-type',
							defaultIndex: indexs[0]
						}
					]
				}
			},
			{ 
				name: '付款方式', 
				value: '',
				active: false,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [2],
				placeholder: '请选择',
				classify: 'payType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values:  ["押一付一", "押一付三", "半年付", "年付", "面议", "押二付一", "押三付一", "押二付三", "押三付三", "押一付二", "押二付二", "押三付二"],
							className: 'house-pay',
							defaultIndex: indexs[0]
						}
					]
				},
			},
			{ 
				name: '租期', 
				value: '',
				active: false,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'periodType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["半年租", "年租", "不限" ],
							className: 'house-only',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	
	// 装修/装修时间（选填）/供暖（选填）配置 (二手房和租房都有)
	{
		id: 'houseConfig',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [BUSINESS, RENTING],
		placeholder: '请选择',
		field: [
			{ 
				name: '装修', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [2],
				classify: 'decorateType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["毛坯", "普通装修", "中装", "精装修", "豪华装修"],
							className: 'house-decorate',
							defaultIndex: indexs[0]
						}
					]
				}
			},
			{ 
				name: '装修时间', 
				value: '',
				active: false,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [2],
				placeholder: '请选择',
				classify: 'decorateDateType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["1年内", "3年内", "5年内", "5年前"],
							className: 'house-decorate-time',
							defaultIndex: indexs[0]
						}
					]
				},
			},
			{ 
				name: '供暖', 
				value: '',
				active: false,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'heatingType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["自供暖", "集中供暖", "不供暖" ],
							className: 'house-heating',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	// 入住时间 配置 (仅租房有)
	{
		id: 'check-time',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [ RENTING ],
		placeholder: '请选择',
		field: [
			{ 
				name: '入住时间', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [1],
				classify: 'checkInTimeType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["随时", "一周内", "一月内"],
							className: 'house-decorate',
							defaultIndex: indexs[0]
						}
					]
				}
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	// 看房时间/房屋情况（选填）(二手房和租房都有)
	{
		id: 'houseTime',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [BUSINESS, RENTING],
		placeholder: '请选择',
		field: [
			{ 
				name: '看房时间', 
				value: '',
				active: true,
				type:'text',
				required: true,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [1],
				classify: 'propertyType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["随时可看", "提前预约", "不方便看"],
							className: 'house-time',
							defaultIndex: indexs[0]
						}
					]
				}
			},
			{ 
				name: '房屋情况', 
				value: '',
				active: false,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [2],
				placeholder: '请选择',
				columns: function() {
					let indexs = this.defaultIndexs
					return [
						{
							values: ["空置", "租客在住", "业主自住", "钥匙在手"],
							className: 'house-situation',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	// 车位（选填）/学位（选填）/地铁（选填） (仅二手房有)
	{
		id: 'houseOther',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [ BUSINESS ],
		placeholder: '请选择',
		field: [
			{ 
				name: '车位', 
				value: '',
				active: true,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [2],
				classify: 'parkingSpaceType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["私家车位", "固定车位", "月卡车位", "临时卡车位"],
							className: 'house-parking',
							defaultIndex: indexs[0]
						}
					]
				}
			},
			{ 
				name: '学位', 
				value: '',
				active: false,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'rentalTags_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["无学位", "学位可用", "学位占用"],
							className: 'house-degree',
							defaultIndex: indexs[0]
						}
					]
				},
			},
			{ 
				name: '地铁', 
				value: '',
				active: false,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'metroType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["无地铁", "近地铁"],
							className: 'house-metro',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
	// 车位（选填）/地铁（选填） (仅租房有)
	{
		id: 'houseOther',
		event: 'click',
		output: 'format',
		type: 'input',
		isReadonly: true,
		isPicker: true,
		apply: [ RENTING ],
		placeholder: '请选择',
		field: [
			{ 
				name: '车位', 
				value: '',
				active: true,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				placeholder: '请选择',
				defaultIndexs: [2],
				classify: 'parkingSpaceType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["私家车位", "固定车位", "月卡车位", "临时卡车位"],
							className: 'house-parking',
							defaultIndex: indexs[0]
						}
					]
				}
			},
			{ 
				name: '地铁', 
				value: '',
				active: false,
				type:'text',
				required: false,
				isReadonly: true,
				isEmpty: false,
				defaultIndexs: [1],
				placeholder: '请选择',
				classify: 'metroType_list',
				columns: function() {
					let indexs = this.defaultIndexs
					let values = getOptionList(this.classify)
					return [
						{
							values,
							// values: ["无地铁", "近地铁"],
							className: 'house-metro',
							defaultIndex: indexs[0]
						}
					]
				},
			}
		],
		plugin: function(values) {
			return values.join('')
		}
	},
]

export default basicData